package com.yanqu.road.server.cmd.chefduel.process3.cross;

import com.yanqu.road.entity.activity.chefduel.process3.ChefDuel3OpenItem;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelActivityMgr;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_CROSS_CHEF_DUEL3_OPEN_BANQUET, desc = "开宴会回来扣道具")
public class CrossJoinBanquetOpenCmd extends AbstractCommand {

	int banquetId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ChefDuelProto.CrossChefDuel3OpenBanquetRespMsg crossRespMsg = ChefDuelProto.CrossChefDuel3OpenBanquetRespMsg.parseFrom(packet.getBytes());
		int activityId = crossRespMsg.getActivityId();
		int itemId = crossRespMsg.getItemId();
		long userId = crossRespMsg.getUserId();
		ret = crossRespMsg.getRet();
		ChefDuel3OpenItem cookBoy3OpenItem = ChefDuelActivityMgr.getChefDuel3OpenItem(activityId,itemId);
		player.getModule(PreReduceModule.class).restorePreReduce(cookBoy3OpenItem.getConsume());
		if(ret == 0){
			banquetId = crossRespMsg.getBanquetId();
			GamePlayer openUser = GamePlayerMgr.getPlayer(userId);
			openUser.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(cookBoy3OpenItem.getConsume()), eLogMoneyType.ChefDuel,eLogMoneyType.CrossChefDuel3OpenBanquetConsume);
			ChefDuelMgr.openBanquetAddCondition(activityId,userId);
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		ChefDuelProto.ChefDuel3OpenBanquetRespMsg.Builder respMsg = ChefDuelProto.ChefDuel3OpenBanquetRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(ret == 0){
			respMsg.setBanquetId(banquetId);
		}
		player.sendPacket(Protocol.U_CHEF_DUEL3_OPEN_BANQUET, respMsg);
	}
}
